package com.financial.sys.service.repayment.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.financial.sys.mapper.repayment.TRepaymentDetailMapper;
import com.financial.model.pojo.TRepaymentDetail;
import com.financial.sys.service.repayment.TRepaymentDetailService;
import com.financial.sys.vo.repayment.TRepaymentDetailQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author hzy
 * @since 2020-02-12
 */
@Service
public class TRepaymentDetailServiceImpl extends ServiceImpl<TRepaymentDetailMapper, TRepaymentDetail> implements TRepaymentDetailService {

    @Autowired
    TRepaymentDetailMapper TRepaymentDetailMapper;

    @Override
    public List<TRepaymentDetail> selectByBorrowUserId(String BorrowUserId) {
        QueryWrapper<TRepaymentDetail> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("borrow_user_id",BorrowUserId);
        List<TRepaymentDetail> tRepaymentDetails = baseMapper.selectList(queryWrapper);
        return tRepaymentDetails;
    }

    @Override
    public IPage query(TRepaymentDetailQuery TRepaymentDetailQuery) {
       QueryWrapper<TRepaymentDetail> queryWrapper = new QueryWrapper<>();
        if (queryWrapper==null){
            baseMapper.selectList(null);
        }
        //判断是否为当前页
        if (TRepaymentDetailQuery.getCurrentPage()==null){
            TRepaymentDetailQuery.setCurrentPage(1);
        }
        Integer CurrentPage=TRepaymentDetailQuery.getCurrentPage();
        Page<TRepaymentDetail> page = new Page<>(CurrentPage,5);
        //条件筛选
        String beginDate = TRepaymentDetailQuery.getBeginDate();
        String endDate = TRepaymentDetailQuery.getEndDate();
        Integer repaymentType = TRepaymentDetailQuery.getRepaymentType();
        if (beginDate!=null){
            queryWrapper.ge("repayment_time",beginDate);
        }
        if (endDate!=null){
            queryWrapper.le("repayment_time",endDate);
        }
        if (repaymentType!=null){
            queryWrapper.eq("repayment_type",repaymentType);
        }
        IPage<TRepaymentDetail> tRepaymentDetailIPage = TRepaymentDetailMapper.selectPage(page, queryWrapper);
        return tRepaymentDetailIPage;
    }
}
